<template>
	<view class="content">
		<search class="search-main" @search="searchHandle"/>
		<!-- 轮播 -->
		<swiper class="screen-swiper" style="margin-top: 100upx;" :class="dotStyle?'square-dot':'round-dot'"
			:indicator-dots="true" :circular="true" :autoplay="true" interval="5000" duration="500">
			<swiper-item v-for="(item,index) in swiperList" :key="item.id">
				<image :src="item.url" mode="aspectFill"></image>
			</swiper-item>
		</swiper>
		<view class="  movie-list">
			<view class="list-item flex" v-for="item in filmList">
				<image :src="item.filmCover" mode=""></image>
				<view class="text-wrap  flex flex-direction  flex-treble margin-left-xs">
					<text class="margin-top-xs text-lg">{{item.filmName}}</text>
					<text class="text-xs text-gray margin-top-xs">{{item.filmSort}}</text>
					<text></text>
				</view>
				<view class="right-wrap text-center flex flex-direction flex-sub justify-around">
					<text>8分</text>
					<button size="mini" class="buy-button text-white bg-red" @tap="ticket(item)">购票</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dotStyle: true,
				filmList: [],
				list:[],
				swiperList: [{
					id: 0,
					url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big84000.jpg'
				}, {
					id: 1,
					url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big37006.jpg',
				}, {
					id: 2,
					url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big39000.jpg'
				}, {
					id: 3,
					url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big10001.jpg'
				}]
			}
		},
		onLoad() {
			this.getMovieList()
			this.getSwiperList()
		},
		methods: {
			getSwiperList() {
				//请求获得轮播数据
				this.$ajax.get('/film/film/getHomeData').then(res => {
					if (res.code === 0) {
						this.swiperList = res.data
					}
				})
			},
			getMovieList() {
				this.$ajax.get('/film/film/list', {
					t: '1684057983816',
					page: 1,
					limit: 10
				}).then(res => {
					console.log(res.page.list);
					this.list = res.page.list
					this.filmList = this.list
				})
			},
			searchHandle(key){
				if(key===''){
					this.filmList = this.list
				}
				let reg = new RegExp(`${key}`)
			    this.filmList = this.list.filter((item)=>{
					if(reg.test(item.filmName) ){
						return true
					}else{
						return false
					}
				})
			},
			ticket(item) {
				uni.setStorage({
					key:'data',
					data:item,
					success() {
						uni.navigateTo({
							url:'/pages/cinemaDetail/cinemaDetail'
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		height: 100%;
	}
	
	.search-main {
		// margin-top: 50rpx
	}

	.movie-list {
		margin-top: 50rpx;
		padding: 0 10upx;
		padding-bottom: 50upx;

		.list-item {
			margin-top: 50rpx;
			width: 100%;
			height: 200upx;

			image {
				height: 100%;
				width: 300rpx;
			}
		}
	}
</style>
